package com.hncgy.xzf.jdapi.service.product.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hncgy.xzf.jdapi.domain.product.po.Products;
import com.hncgy.xzf.jdapi.domain.product.vo.ProductDetailsVO;
import com.hncgy.xzf.jdapi.domain.product.vo.ProductSeckillVO;
import com.hncgy.xzf.jdapi.mapper.product.ProductsMapper;
import com.hncgy.xzf.jdapi.service.product.IProductsService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author 不会代码的蜡笔
 * @since 2025-10-31
 */
@Service
public class ProductsServiceImpl extends ServiceImpl<ProductsMapper, Products> implements IProductsService {

    @Autowired
    private ProductsMapper productsMapper;

    @Override
    public ProductDetailsVO selectProductDetailsById(Integer productId) {
        return productsMapper.selectProductDetailsById(productId);
    }

    @Override
    public ProductSeckillVO selectSeckillDetailsById(Integer productId, Integer promotionId) {
        ProductSeckillVO productSeckillVO = productsMapper.selectSeckillDetailsById(productId, promotionId);
        if (productSeckillVO != null){
            productSeckillVO.getSkus().forEach(sku -> {
                sku.setPrice(sku.getSeckillPrice());
            });
        }
        return productSeckillVO;
    }
}
